<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="d3.v5.min.js"></script>
  <style>
    .container {
      width: 200px;
      height: 200px;
      background: #efefef;
    }
  </style>
</head>

<body>
  <div id="app">
    <p>1</p>
    <p>2</p>
    <p>3</p>
    <p>4</p>
    <p>5</p>
  </div>

  <script>

    var dataset = [10, 20, 30, 40, 50];
    var container = d3.select("#app");
    container.selectAll('p')
      //绑定数据源
      .data(dataset)
      .text(function (d, i) {
        return d;
      })
      .style('color', (d, i) => {
        if (d > 20) {
          return 'red'
        } else {
          return 'green'
        }
      })

  </script>

</body>

</html>